﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PMPUtils.DB;

namespace PMPUtils.Maintenance
{
    public class SprintMaintain
    {
        public static void AddSprint(String sprint, String sprintStart, String NF1Capacity,
            String NF2Capacity, String NF1CapacityNotes, String NF2CapacityNotes)
        {
            String strInsert = "insert into sprint (sprint, NF1capacity, NF2capacity, NF1capacity_note, NF2capacity_note, sprintstart, iscompleted, isleftovercreated)  values " +
                " ( " +
                "'" + sprint + "', " + NF1Capacity + ", " + NF2Capacity + ", '" + NF1CapacityNotes + "', '" + NF2CapacityNotes + "', '" + sprintStart + "', 0, 0)";

            DBOperator localOperator = new DBOperator(DBConfigurations.LOCAL_CONNECTION_STRING);
            localOperator.Update(strInsert);
        }

        public static bool IsSprintAlreadyExists(String sprint)
        {
            String strQuery = "select count(id) exist from sprint where sprint = '" + sprint + "'";
            DBOperator localOperator = new DBOperator(DBConfigurations.LOCAL_CONNECTION_STRING);
            DataTable dtExists = localOperator.Read(strQuery);

            bool isExists = false;

            foreach (DataRow row in dtExists.Rows)
            {
                if (row["exist"] != DBNull.Value)
                {
                    if (Convert.ToInt32(row["exist"]) >= 1)
                    {
                        isExists = true;
                    }
                }
            }

            return isExists;
        }
    }
}
